package com.carkeeper.order.controller;

import com.carkeeper.entity.PageResult;
import com.carkeeper.entity.Result;
import com.carkeeper.entity.StatusCode;
import com.carkeeper.order.pojo.Accounts;
import com.carkeeper.order.service.AccountsService;
import com.github.pagehelper.Page;
import com.sun.org.apache.regexp.internal.RE;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/accounts")
@Api("结算单查询接口api")
@CrossOrigin
public class AccountsController {

    @Autowired
    private AccountsService accountsService;

    /**
     * 分页+条件查询结算表
     * @param searchMap
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/{page}/{pageSize}")
    @ApiOperation("分页+条件查询结算表")
    public Result accountsPage(@RequestParam(required = false) Map<String, Object> searchMap, @PathVariable("page") int page, @PathVariable("pageSize") int pageSize){
        Page<Accounts> pageList = accountsService.accountsPage(searchMap,page, pageSize);
        PageResult pageResult = new PageResult(pageList.getTotal(),pageList.getResult());
        return new Result(true, StatusCode.OK,"查询成功",pageResult);
    }

    /**
     * 添加结算单
     * @param accounts
     * @return
     */
    @PostMapping
    @ApiOperation("添加结算单")
    public Result addAccounts(@RequestBody Accounts accounts){
        accountsService.addAccounts(accounts);
        return new Result(true, StatusCode.OK,"添加结算表成功");
    }

    /**
     * 查看当前日期总结算金额
     * @param date
     * @return
     */
    @GetMapping("/moneyByTime")
    @ApiOperation("查看当前日期总结算金额")
    public Result moneyByTime(String date){
        Integer money = accountsService.moneyByTime(date);
        return new Result(true, StatusCode.OK,"查询成功",money);
    }
}
